﻿#Region "Copyright"
'————————————————————————————————————————
'	创建人员(Creator)    ：Huangyd
'	创建日期(Date)       ：2012-07-14
'   联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
'   描    述(Description)：
'
'	Copyright (C) 2012 ajayumi 版权所有
'————————————————————————————————————————
#End Region
Imports System.Drawing.Drawing2D
Imports System.Drawing

Namespace Drawing
    ''' <summary>
    ''' 使用呈现质量的优化类
    ''' </summary>
    Public Class OptimizeGraphics
        Implements IDisposable

        Private m_SmoothingMode As SmoothingMode = SmoothingMode.None
        Private m_Graphics As Graphics = Nothing

        Public Sub New(ByVal g As Graphics)
            Me.m_Graphics = g
            Me.m_SmoothingMode = g.SmoothingMode

            g.SmoothingMode = SmoothingMode.AntiAlias
        End Sub

        Public Sub New(ByVal g As Graphics, ByVal mode As SmoothingMode)
            Me.m_Graphics = g
            Me.m_SmoothingMode = g.SmoothingMode
            Select Case mode
                Case SmoothingMode.AntiAlias
                Case SmoothingMode.HighQuality
                    g.SmoothingMode = mode
                    Exit Select
                Case Else
                    g.SmoothingMode = SmoothingMode.AntiAlias
            End Select
        End Sub

        Private disposedValue As Boolean = False        ' 检测冗余的调用

        ' IDisposable
        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
                    ' TODO: 释放其他状态(托管对象)。
                End If

                ' TODO: 释放您自己的状态(非托管对象)。
                ' TODO: 将大型字段设置为 null。
                Me.m_Graphics.SmoothingMode = Me.m_SmoothingMode
            End If
            Me.disposedValue = True
        End Sub

#Region " IDisposable Support "
        ' Visual Basic 添加此代码是为了正确实现可处置模式。
        Public Sub Dispose() Implements IDisposable.Dispose
            ' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean) 中。
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region

    End Class

End Namespace
